package com.bridgeintelligent.tag.webserver.dim.mgmt.service.mine;

import com.bridgeintelligent.tag.webserver.dim.mgmt.api.DimRep;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by JackCheung on 2019/9/13 4:04 PM.
 */
@Api(tags = "我的标签")
@RestController
@RequestMapping("api/dimMine")
public class DimMineController {

    private IDimMineService iDimMineService;

    public DimMineController(IDimMineService iDimMineService) {
        this.iDimMineService = iDimMineService;
    }

    @ApiOperation(value = "获取我的标签列表", notes = "我的标签")
    @GetMapping("list")
    public DimRep list(Integer pageNumber, Integer pageSize, String dimName, String department, String theme, String createTimeStart, String createTimeEnd, String uptTimeStart, String uptTimeEnd) {
        pageNumber = pageNumber == null ? 1 : pageNumber;
        pageSize = pageSize == null ? 0 : pageSize;
        if (StringUtils.isNotEmpty(createTimeStart)) {
            createTimeStart = createTimeStart + " 00:00:00";
        }
        if (StringUtils.isNotEmpty(createTimeEnd)) {
            createTimeEnd = createTimeEnd + " 23:59:59";
        }
        if (StringUtils.isNotEmpty(uptTimeStart)) {
            uptTimeStart = uptTimeStart + " 00:00:00";
        }
        if (StringUtils.isNotEmpty(uptTimeEnd)) {
            uptTimeEnd = uptTimeEnd + " 23:59:59";
        }
        return iDimMineService.list(pageNumber, pageSize, dimName, department, theme, createTimeStart, createTimeEnd, uptTimeStart, uptTimeEnd);
    }

    @ApiOperation(value = "增加我的标签收藏", notes = "我的标签")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "query", name = "dimId", value = "标签ID", required = true)})
    @PostMapping("add")
    public DimRep add(String dimId) {
        return iDimMineService.add(dimId);
    }

    @ApiOperation(value = "取消我的标签收藏", notes = "我的标签")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "query", name = "dimId", value = "标签ID", required = true)})
    @PostMapping("del")
    public DimRep del(String dimId) {
        return iDimMineService.del(dimId);
    }
}
